package com.yhsimon.composite;

import java.util.ArrayList;
import java.util.List;

/**
 * @author： YHSimon
 * @date： 2021-09-02 16:17
 */
public class College extends OrganizationComponent{
    //List中存放的是Department
    List<OrganizationComponent> organizationComponents=new ArrayList<OrganizationComponent>();

    //构造器
    public College (String name, String des) {
        super(name, des);
    }

    //重写add方法
    @Override
    protected void add(OrganizationComponent organizationComponent) {
        //实际业务中，College的add和University的add方法不一定完全相同
        organizationComponents.add(organizationComponent);
    }

    //重写remove方法
    @Override
    protected void remove(OrganizationComponent organizationComponent) {
        organizationComponents.remove(organizationComponent);
    }

    @Override
    public String getDes() {
        return super.getDes();
    }

    @Override
    public String getName() {
        return super.getName();
    }

    //print方法，就是输出University包含的学院
    @Override
    public void print() {
        System.out.println("----------"+getName()+"--------");
        //遍历
        for (OrganizationComponent organizationComponent : organizationComponents) {
            organizationComponent.print();
        }
    }
}
